package com.garygyp.staservice.schedule;

import com.garygyp.staservice.service.StatisticsDailyService;
import com.garygyp.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author GaryGyp
 * @date 2022/5/21 17:29
 * @description
 */
@Component
public class ScheduleTask {
//    // 每隔五秒执行这个方法
//    @Scheduled(cron = "0/5 * * * * ? ")
//    public void task1() {
//        System.out.println("**********task1执行了**********");
//    }

    @Autowired
    private StatisticsDailyService dailyService;

    // 在每天凌晨1点执行方法，把前一天的数据查询进行添加
    // 指定cron表达式规则
    @Scheduled(cron = "0 0 1 * * ? ")
    public void task02() {
        dailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }

}
